var Download = {
	inOpCode: 1,
    DOWNLOAD: "wgt://data/",
    downloadPath: "",
    savedPath: "",
    callback: null,
	download: function(downloadPath, savedPath, callback, resume) {
        Download.inOpCode = Math.floor(Math.random() * ( 100000 + 1));
        Download.downloadPath = downloadPath;
        Download.savedPath = Download.DOWNLOAD+savedPath;
        Download.callback = callback;
        Download.resume = Download.resume ? "1":"0";

        //下载状态监听方法
        uexDownloaderMgr.onStatus = function(opCode, fileSize, percent, status){
            switch (status) {
                case 0://下载过程中
					uexWindow.toast("1", "5", "正在下载："+percent + "%", "0");
                    break;
                case 1://下载完成
					uexWindow.toast("0", "5", "下载完成，准备打开", "2000");
                    uexDownloaderMgr.closeDownloader(opCode);//下载完成要关闭下载对象
                    Download.callback(status);
                    break;
                case 2://下载失败
                    // alert("下载失败");
                    uexDownloaderMgr.closeDownloader(opCode);//下载失败要关闭下载对象
                    break;
            }
        }
        var cText = 0;
        var cJson = 1;
        var cInt = 2;
        //创建下载对象的回调方法
        uexDownloaderMgr.cbCreateDownloader = function(opCode, dataType, data){
            switch (dataType) {
                case cText:
                    alert("uex.cText");
                    break;
                case cJson:
                    alert("uex.cJson");
                    break;
                case cInt:
                    if (data == 0) {
                        // alert("创建成功");
						// alert(Download.url);
                        uexDownloaderMgr.download(Download.inOpCode, Download.downloadPath, Download.savedPath, Download.resume);
                    }
                    else {
                        // alert("创建失败");
                    }
                    break;
                default:
                    alert("error");
            }
        }
        uexWidgetOne.cbError = function(opCode, errorCode, errorInfo){
            alert(errorInfo);
        }
        // 通过下载url获取下载对象的信息的回调方法
        uexDownloaderMgr.cbGetInfo = function(opCode, dataType, data){
            switch (dataType) {
                case cText:
                    alert("uex.cText");
                    break;
                case cJson:
                    if (data == null || data.length == 0) {
                        alert("无数据");
                        return;
                    }
                    alert(info.savePath);
                    // var info = eval('(' + data + ')');
                    // alert(data);
                    // document.getElementById('fileInfo').innerHTML = "文件路径：" + info.savePath + "<br>文件大小：" + info.fileSize + "<br>已下载：" + info.currentSize + "<br>下载时间：" + info.lastTime;
                    break;
                case cInt:
                    alert("uex.cInt");
                    break;
                default:
                    alert("error");
            }
        }
        uexDownloaderMgr.createDownloader(Download.inOpCode);
	},
    //通过操作ID关闭下载对象
    closeDownload: function() {
        uexDownloaderMgr.closeDownloader(Download.inOpCode);
    },
    //通过路径获取下载的文件信息
    getInfo: function() {
        uexDownloaderMgr.getInfo(Download.downloadPath);
    },
    // 通过路径清除未完成下载的任务
    clearInfo: function() {
        uexDownloaderMgr.clearTask(Download.downloadPath, "1");
    }
}